/**
 * create by young (young2f@outlook.com) on 2023/7/1
 */
'use strict';
import React from 'react';
import {Button, Form, Input, InputNumber, notification, Select, Switch} from 'antd';
import moment from 'moment';
import 'moment/locale/zh-cn';
import {FormField, FormLayout, ModalFooter} from 'antd-extra';
import FormBase from '../../components/Base/FormBase';
import DescGroup from '../../components/DescriptionGroup';

moment.locale('zh-cn');

@Form.create()
export default class ModalLabelCreate extends FormBase {
  constructor(props) {
    super(props);
    this.state = {};
  }

  componentDidMount() {
    this.onLoadData().then(res => this.setState(res));
  }

  /**
   * unique:唯一标识/是新建不是编辑
   * {key:code,table:product,prefix:PRD}
   * @returns {Promise<{dynamicLabels: *}>}
   */
  async onLoadData() {
    let {table, page, dispatch,  values = {}} = this.props;
    const payload = {table, page};
    const labelsRes = await dispatch(
      {type: 'dynamicLabel/getLabels', payload},
    );

    const dynamicLabels = labelsRes && labelsRes.result ? labelsRes.result : [];
    this.getDLabelDetail(dynamicLabels,values)
    return {dynamicLabels, values};
  }

  renderFoot = () => {
    const {foot, value, modalRef, form} = this.props;
    if (foot) {
      return foot(value, modalRef);
    } else {
      return (
        <ModalFooter>
          <Button onClick={() => {
            modalRef.close();
          }}>取消</Button>
        </ModalFooter>
      );
    }
  };

  render() {
    const {form, footDisabled, style, beforeForm, afterForm, disabledProps, cols = 2} = this.props;
    const {dynamicLabels=[], values={}} = this.state;
    const formProps = {beforeForm, afterForm, disabledProps, width: '90%'};

    return (
      <div style={{...style}}>
        <DescGroup
          {...{
            labels:dynamicLabels,
            values,
            size: 'small',
            column: cols,
          }}
        ></DescGroup>
        {!footDisabled && this.renderFoot()}
      </div>

    );
  }
}

